package com.cyru.statemachine.core.builder.impl;

import com.cyru.statemachine.core.StateMachine;
import com.cyru.statemachine.core.StateMachineConfiguration;
import com.cyru.statemachine.core.StateMachines;
import com.cyru.statemachine.core.builder.StateMachineBuilder;
import com.cyru.statemachine.core.builder.StateMachineConfigurationBuilder;
import com.cyru.statemachine.core.builder.TransitionBuilder;
import com.cyru.statemachine.core.impl.StateMachineConfigurationImpl;
import com.cyru.statemachine.core.impl.StateMachineImpl;
import com.cyru.statemachine.core.impl.States;
/**
 * description:
 *
 * @author zhangxuchuan
 * date 2022/5/2
 */
public class StateMachineBuilderImpl<S, E, C> implements StateMachineBuilder<S, E, C> {
    private final States<S, E, C> states = new States<>();

    private final StateMachineConfiguration<S, E, C> configuration = new StateMachineConfigurationImpl<>();

    private final StateMachineImpl<S, E, C> stateMachine = new StateMachineImpl<>(states, configuration);

    @Override
    public StateMachine<S, E, C> build(String id) {
        stateMachine.setId(id);
        stateMachine.ok();
        StateMachines.register(stateMachine);
        return stateMachine;
    }

    @Override
    public TransitionBuilder<S, E, C> transition() {
        return new TransitionBuilderImpl<>(states);
    }

    @Override
    public StateMachineConfigurationBuilder<S, E, C> configuration() {
        return new StateMachineConfigurationBuilderImpl<>(configuration);
    }
}
